package club.janna.netty.bio;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class BioClient {
    public static void main(String[] args) throws IOException, InterruptedException {
        Socket socket = new Socket("localhost", 8080);
        System.out.println("已连接");
        for(;;) {
            OutputStream outputStream = socket.getOutputStream();
            outputStream.write("Hello, World!".getBytes());
            outputStream.flush();
            InputStream inputStream = socket.getInputStream();
            byte[] bytes = new byte[1024];
            int n;
            if((n = inputStream.read(bytes)) != -1) {
                System.out.println("收到服务器发来的数据：" + new String(bytes, 0, n));
            }
            Thread.sleep(3000L);
        }
    }
}
